<template>
	<!--pages/OrderDetail/OrderDetail.wxml-->
	<view class="main-box">
		<template v-if="infoObj">
			<view class="top-box">
				<image src="/static/images/turntable/line.png" class="line"></image>
				<view class="progress" v-for="(item, index) in ProgressArr" :key="index">
					<image
						:src="item.state?'../../../images/turntable/ellipse_sle.png':'../../../images/turntable/ellipse_nosle.png'"
						class="state-image"></image>
					<view :style="'color:' + (item.state?'#333333':'#999999')">{{item.text}}</view>
				</view>
			</view>
			<view class="award-box">
				<image :src="infoObj.prize_img" class='prize-image'></image>
				<view class="prize-name">
					<text>{{infoObj.prize_name}}</text>
					<text class="prize-type">{{infoObj.prize_type==1?'实物':'门店商品'}}</text>
				</view>
			</view>
			<view v-if="way==1" class="choose-address-box addr-box">
				<view class="pre-info">预留信息</view>
				<view class="info-item pre-info-name">
					<text>姓名</text>
					<text>{{infoObj.username}}</text>
				</view>
				<view class="info-item">
					<text>手机号</text>
					<text>{{infoObj.phone}}</text>
				</view>
			</view>
			<view class="choose-address-box order-info-box">
				<view class="order-info">订单信息</view>
				<view class="info-item order-num-top">
					<text>订单号</text>
					<text>{{infoObj.order_num}}</text>
				</view>
				<view class="info-item">
					<text>领取时间</text>
					<text>{{infoObj.receive_time_conversion}}</text>
				</view>
				<view class="info-item">
					<text>配送方式</text>
					<view>{{way==0?'商家配送':'到店自提'}}</view>
				</view>
				<view class="info-item" v-if="way==1">
					<text>自提时间</text>
					<view>2019.10.21</view>
				</view>
				<view class="info-item" v-if="way==1">
					<text>自提门店</text>
					<view>{{infoObj.shop_name}}</view>
				</view>
				<view class="info-item info-item-top"
					v-if="(ProgressArr[1].state&&way==0)||(ProgressArr[0].state&&way==1)">
					<text></text>
					<view class="store-nav">
						<view class="Stores_navigation" @tap="shop_gps" v-if="way==1">门店导航</view>
						<view class="Logistics_information" @tap="Logistics" :data-way="way">{{way==0?'物流信息':'核销码'}}
						</view>
					</view>
				</view>
			</view>
			<!-- 提货码 -->
			<view class="qrcodealert" v-if="showcode" @touchstart="cancelbarcode">
				<view class="qrcodealertinner">
					<canvas disable-scroll="true" class='canvas-position-top' canvas-id="barcode"></canvas>
					<view class="pick-code-top">{{pick_code}}</view>
				</view>
			</view>

		</template>
	</view>
</template>

<script>
	// pages/OrderDetail/OrderDetail.js
	var app = getApp().globalData;
	var wxbarcode = require("../../../utils/index.js");

	export default {
		data() {
			return {
				way: 0,
				ProgressArr: [],
				infoObj: null,
				showcode: false,
				pick_code: ""
			};
		},

		components: {},
		props: {},

		onLoad(options) {
			console.log('orderDetail:options', options)
			if (options.delivery_type = 1) {
				this.setData({
					ProgressArr: [{
						text: '待发货',
						state: false
					}, {
						text: '已发货',
						state: false
					}],
					way: 0
				});
			} else {
				this.setData({
					ProgressArr: [{
						text: '待自提',
						state: false
					}, {
						text: '已发货',
						state: false
					}],
					way: 1
				});
			}

			getApp().globalData.sendRequest({
				url: '/Turntable/getDeliveryOrder',
				type: "post",
				data: {
					win_id: options.id,
					delivery_type: options.delivery_type
				},
				success: res => {
					if (res.code == 0) {
						let infoObj = res.data;
						infoObj.receive_time_conversion = getApp().globalData.getDate('y-m-d h:i:s', infoObj.receive_time * 1000);

						if (infoObj.delivery_status == 1) {
							this.ProgressArr[0].state = true;
						} else {
							this.ProgressArr[1].state = true;
						}

						this.setData({
							infoObj: infoObj,
							ProgressArr: this.ProgressArr
						});
					}
				}
			});
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},
		methods: {
			/**
			 * 生命周期函数--监听页面加载
			 */
			shop_gps() {
				uni.openLocation({
					longitude: parseFloat(this.infoObj.shop_lng),
					latitude: parseFloat(this.infoObj.shop_lat),
					name: this.infoObj.shop_name
				});
			},

			Logistics(e) {
				var way = e.currentTarget.dataset.way;

				if (way == 0) {
					uni.navigateTo({
						url: '../logistics/logistics?order_no=' + this.infoObj.order_num + '&type=9999'
					});
				} else if (way == 1) {
					var pick_code = this.infoObj.receive_code;
					wxbarcode.barcode('barcode', pick_code, 600, 200);
					this.setData({
						pick_code: pick_code,
						showcode: true
					});
				}
			},

			cancelbarcode() {
				// 关闭提货码
				if (this.showcode) {
					this.setData({
						showcode: false
					});
				}
			}

		}
	};
</script>
<style>
	@import "./OrderDetail.css";
</style>
